//
//  LockBase.swift
//  sinaDemo
//
//  Created by admin on 2021/7/9.
//

import UIKit

class LockBase: NSObject {
    var money:Int = 100
    var ticket:Int = 100
    func testAll() {
        testTickets()
        testMoney()
    }
    func testMoney() {
        for _ in 0...9 {
            DispatchQueue.global().async {
                self.payMoney()
            }
        }
        for _ in 0...9 {
            DispatchQueue.global().async {
                self.saveMoney()
            }
        }
        
    }
    func testTickets() {
        for _ in 0...9 {
            DispatchQueue.global().async {
                self.saleTickets()
            }
        }
    }
    
    func payMoney() {
        money -= 1
        print("payMoney剩余钱数\(money)")
    }
    func saveMoney() {
        money += 5
        print("saveMoney剩余钱数\(money)")
    }
    func saleTickets() {
        ticket -= 1
        print("saleTickets c剩余票数\(ticket)")
    }
}
